﻿// test_12.4.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>

int map[50][50];
char x, m[] = ".XO";
int y, tmp = 2;
int dx[] = { 1, 1, 0, -1, -1, -1, 0, 1 };
int dy[] = { 0, -1, -1, -1, 0, 1, 1, 1 };
int check() {
    for (int i = 16; i <= 30; ++i) {
        for (int j = 16; j <= 30; ++j) {
            for (int k = 0; k < 8; ++k) {
                int cnt[] = { 0, 0, 0 };
                for (int l = 0; l < 5; ++l)
                    cnt[map[i + dx[k] * l][j + dy[k] * l]]++;
                if (cnt[1] == 5) return 1;
                if (cnt[2] == 5) return 2;
            }
        }
    }
    return 0;
}

void printMap() {
    printf("----------------------------------------------");
    for (int i = 0; i < 15; ++i) {
        printf("\n%c", i + 'A');
        for (int j = 0; j < 15; ++j)
            printf("  %c", m[map[i + 16][j + 16]]);
    }
    printf("\n ");
    for (int i = 1; i <= 15; ++i) printf(" %2d", i);
    printf("\n----------------------------------------------\n");
}

int main() {
    while (scanf(" %c%d", &x, &y)) {
        map[x - 'A' + 16][y + 15] = (tmp ^= 3);
        int res = check();
        if (res != 0) {
            printMap();
            printf("~~~~~~~~~~~~~~~~~~~ %c Wins!~~~~~~~~~~~~~~~~~~~", m[res]);
            return 0;
        }
    }
    return 0;
}

